var gorecharge=function(msg){
	layer.open({
			content:msg,
			shadeClose:false,
			btn:['确定','取消'],
			yes:function(){
				var link=serhost+'call.html?module=hn&method=index&customerId='+_customerId+'#/account/0';
				window.location.href=link;
			}
	})
}
var goreg=function(msg){
	if(_refereeId)
		{
			var str='&refereeId='+_refereeId;
		}
		else
		{
			var str="";
		}
		layer.open({
			content:msg,
			shadeClose:false,
			btn:['确定','取消'],
			yes:function(){
				var link=serhost+'call.html?module=hn&method=index&customerId='+_customerId+str+'#/hnindex';
				window.location.href=link;
			}
		})
}

//识别路由跳转
var routerAuth=function(path){
	if(isbase==1&&iscondition==1)
			  	{
			  		if(path.indexOf('reg_')>=0||path.indexOf('agent')>=0||path.indexOf('hnindex')>=0)
			  		{
			  			location.href='#/pindex/0';
			  		}
			  		
			  	}
			  	else if(isbase==0)
			  	{
			  		
			  		if(path!='hnindex'&&path!='loveIndex')
			  		{
			  			if(path=='pindex'||path=='account'||path=='discover')
			  			{
			  				if(ishn==0)
			  				{
			  					location.href='#/hnindex';
//			  					$state.go('hnindex');
			  				}
			  			}
			  			else
			  			{
			  				location.href='#/hnindex';
//			  				$state.go('hnindex');
			  			}
			  			
			  		} 
			  		
			  	}
}

//不同密友圈的cookies标识
var getcookiesQid=function(){
	var _cookiesQid=document.getElementById('qid').value;
	return _cookiesQid
}
//首字母大写
function UpperFirstLetter(str)   
{   
   return str.replace(/\b\w+\b/g, function(word) {   
   return word.substring(0,1).toUpperCase( ) +  word.substring(1);   
 });   
}

function parseUA() {
	            var u = navigator.userAgent;
	            var u2 = navigator.userAgent.toLowerCase();
	            return { //移动终端浏览器版本信息
	                trident: u.indexOf('Trident') > -1, //IE内核
	                presto: u.indexOf('Presto') > -1, //opera内核
	                webKit: u.indexOf('AppleWebKit') > -1, //苹果、谷歌内核
	                gecko: u.indexOf('Gecko') > -1 && u.indexOf('KHTML') == -1, //火狐内核
	                mobile: !!u.match(/AppleWebKit.*Mobile.*/), //是否为移动终端
	                ios: !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/), //ios终端
	                android: u.indexOf('Android') > -1 || u.indexOf('Linux') > -1, //android终端或uc浏览器
	                iPhone: u.indexOf('iPhone') > -1, //是否为iPhone或者QQHD浏览器
	                iPad: u.indexOf('iPad') > -1, //是否iPad
	                webApp: u.indexOf('Safari') == -1, //是否web应该程序，没有头部与底部
	                iosv: u.substr(u.indexOf('iPhone OS') + 9, 3),
	                weixin: u2.match(/MicroMessenger/i) == "micromessenger",
	                ali: u.indexOf('AliApp') > -1,
	            };
	        }


//公共方法
var buildUrl = function(type, module, method, params,fromcustomerId) {
		if(typeof(fromcustomerId)=="undefined")
		{
			var cus=_customerId;
		}
		else
		{
			var cus=fromcustomerId;
		}
	
		params = encodeURIComponent(JSON.stringify(params));
		var _URL = "call." + type + "?customerId=" + cus + '&module=' + module + '&method=' + method + '&params=' + params;
		return _URL;
	}

//iframe加载完成公共方法适应高度
function iframeLoad(_class){
	layer.closeAll();
	var height=document.documentElement.clientHeight,
		width=document.documentElement.clientWidth;
	console.log(document.getElementsByClassName(_class));
	document.getElementsByClassName(_class)[0].style.display='block';
	document.getElementsByClassName(_class)[0].style.width=width+'px';
	document.getElementsByClassName(_class)[0].style.height=height+'px';
}

//文档的总高度
function getScrollHeight() {
		var scrollHeight = 0,
			bodyScrollHeight = 0,
			documentScrollHeight = 0;
		if (document.body) {
			bodyScrollHeight = document.body.scrollHeight;
		}
		if (document.documentElement) {
			documentScrollHeight = document.documentElement.scrollHeight;
		}
		scrollHeight = (bodyScrollHeight - documentScrollHeight > 0) ? bodyScrollHeight : documentScrollHeight;
		return scrollHeight;
	}

function getWindowHeight() {　　
		var windowHeight = 0;　　
		if (document.compatMode == "CSS1Compat") {　　　　
			windowHeight = document.documentElement.clientHeight;　　
		} else {　　　　
			windowHeight = document.body.clientHeight;　　
		}　　
		return windowHeight;
	}

function getScrollTop() {　　
	var scrollTop = 0,
		bodyScrollTop = 0,
		documentScrollTop = 0;　　
	if (document.body) {　　　　
		bodyScrollTop = document.body.scrollTop;　　
	}　　
	if (document.documentElement) {　　　　
		documentScrollTop = document.documentElement.scrollTop;　　
	}　　
	scrollTop = (bodyScrollTop - documentScrollTop > 0) ? bodyScrollTop : documentScrollTop;　　
	return scrollTop;
}


function setCookie(name,value,time)
{ 
    var strsec = getsec(time); 
    var exp = new Date(); 
    exp.setTime(exp.getTime() + strsec*1); 
    document.cookie = getcookiesQid() + "-" + name + "="+ escape (value) + ";expires=" + exp.toGMTString(); 
} 
function getsec(str)
{ 
   var str1=str.substring(1,str.length)*1; 
   var str2=str.substring(0,1); 
   if (str2=="s")
   { 
        return str1*1000; 
   }
   else if (str2=="h")
   { 
       return str1*60*60*1000; 
   }
   else if (str2=="d")
   { 
       return str1*24*60*60*1000; 
   } 
} 

//读取cookies 
function getCookie(name) 
{ 
	name=getcookiesQid() + "-" + name;
    var arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)");
 
    if(arr=document.cookie.match(reg))
 
        return unescape(arr[2]); 
    else 
        return null; 
} 

//删除cookies 
function delCookie(name) 
{ 
	name=getcookiesQid() + "-" + name;
    var exp = new Date(); 
    exp.setTime(exp.getTime() - 1); 
    var cval=getCookie(name); 
    if(cval!=null) 
        document.cookie= name + "="+cval+";expires="+exp.toGMTString(); 
} 


function matchobj(attribute,obj){
	for(var i=0;i<obj.length;i++)
	{
		if(obj[i].id==attribute)
		{
			return obj[i]
		}
	}
}
